1. Overview
Recently engaged in Huawei's CDN (-_-| | -_-|| -_-|| ), less time to write things. I recently learned to use Aforge on C # to record camera video and compress the code with interest. Overall, the third party. NET Visual Development library is relatively stable (aforge lib download, offline help document download). However, because this Third-party library maintenance is not good, resulting in incompatibility problems. Here to share these with you, hope to help you.
There are a numbe
everyone's imagination.
The following buttons start the camera, stop, and take the current image.
Okay, the UI is so simple. Next, let's look at the key code.
CaptureSource source;source = new CaptureSource();
First, we instantiate a capturesource as the camera/microphone source. It can be used as the source of videobrush.
VideoCaptureDevice vcd ;vcd = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
Then we will use the static method of th
Use AForge. NET for video collection and aforge.net for video collection
AForge. NET is designed based on C # And has powerful functions in computer vision and AI. Btw... it's an open source framework. Attached to the official website address: http://www.aforgenet.com/aforge/framework.
Today we will introduce the Video Acquisition Function in AForge. The video here includes inputs from cameras and other devices and inputs from video files.
First, let's take a look at the video source PLAYER: Vid
= videodevices[0];//Select the first one, here you can make flexible changes videocapturedevice VideoSource = new Videocapturedevice ( Videodevices[info. monikerstring); videosource.desiredframesize = new System.Drawing.Size (214, 281); videosource.desiredframerate = 1; Videosourceplayer.videosource = Videosource;videosourceplayer.start ();Turn off the camera:Videosourceplayer.signaltostop (); Videosourcep
This article mainly describes the C # call Aforge implementation of camera video sample code, very practical value, the need for friends can refer to the following
1: First download the library file >>
can also go to the official website to find >>
Download this tutorial full code >>
Output for MP4 need to use the FFmpeg related files, I packed the library has been brought, to the official website to find the library can be found in this directory:
2: Add these references:
3: Two Global varia
{System.Windows.MessageBox.Show ("Please connect the camera");Return}Else{Closecapturedevice ();Mycapturedevice = new Videocapturedevice (Videodevices[0]. monikerstring); The//mycapturedevice type is Videocapturedevice,Mycapturedevice.newframe + = new Newframeeventhandler (mycapturedevice_newframe);Mycapturedevice.desiredframesize = new System.Drawing.Size (436, 360);//436, 360Mycapturedevice.desiredframer
to choose. The key code is as follows: copy the code private void Form1_Load (object sender, EventArgs e) {try {// enumerate all video input devices videoDevices = new FilterInfoCollection (FilterCategory. videoInputDevice); if (videoDevices. count = 0) throw new ApplicationException (); foreach (FilterInfo device in videoDevices) {tscbxCameras. items. add (device. name);} tscbxCameras. selectedIndex = 0;} c Atch (ApplicationException) {tscbxCameras. items. add ("No local capture devices"); vid
added to the Toolbox), AForge. Imaging, AForge. Video, AForge. Video. DirectShow;
Then directly upload the code
private FilterInfoCollection videoDevices; private VideoCaptureDevice videoSource; public int selectedDeviceIndex = 0;
The following figure shows how to obtain a device.
Public FilterInfoCollection GetDevices () {try {// enumerate all video input devices videoDevices = new FilterInfoCollection (FilterCategory. VideoInputDevi
System.Windows.Forms;
Using System.IO;
Using Aforge;
Using Aforge.video;
Using AForge.Video.DirectShow;
Using Aforge.imaging;
Using AForge.Imaging.Filters;
Namespace Camera
{
Public partial class Form1:form
{
private filterinfocollection videodevices;
private Videocapturedevice VideoSource;
private int flag = 1;
private String dirc = System.AppDomain.CurrentDomain.BaseDirectory + "Images"; //Saved directories
Previous projects need to mirror the rollover camera video and use Aforge.net to process the video.The first consideration was to read the image control directly from Aforge.net without a frame of video and then copy it to WPF, which was basically a card, so it gave up.Considering that the picture returned by Aforge.net is bitmap, it is intended to embed WinForm PictureBox directly in WPF to implement the video."Note" If embedding the WinForm window in WPF is not transparent."Xaml"Xmlns= "Http:/
An article about aforge.net specific use and attention to the place.
1, get all the cameras on the device:
private void Mainwindow_loaded (object sender, RoutedEventArgs e){Set the initial video deviceVideodevices = new Filterinfocollection (filtercategory.videoinputdevice);Xcount = Videodevices.count;if (Videodevices.count > 0){//Default deviceSourceplayer.videosource = new Videocapturedevice (videodevices[0). monikerstring);}Sourceplayer.start ();
enable the user native camera in Silverlight, first add in the interface A "container" Grid to display the video, and then add a button to enable the Cam device, as shown in the figure.
Xaml:1 2 BorderBrush = "Gray" borderthickness = "3" >3 4 5 6 7 VerticalAlignment = "Bottom"8 Width = "Height" = "30"9 Content = "Start Camera"/>
C #: 1 public Videoandaudio ()2 {3 InitializeComponent ();4 this. Btncam. Click + = new Routedeventhandler (Btncam_click);5}67 void Btncam_click (object sender, Route
its Load event, add the detected camera device to the rear ComboBox for the user to choose from, the key code is as follows:
Private void Form1_Load (object sender, EventArgs e)
{
Try
{
Enumerate all video input devices
Videodevices = new Filterinfocollection (filtercategory.videoinputdevice);
if (videodevices.count = 0)
throw new ApplicationException ();
foreach (FilterInfo device in videodevices)
{
TSCBXCAMERAS.ITEMS.ADD (device. Name);
}
Tscbxcameras.selectedindex = 0;
}
catch
Original address: http://blog.csdn.net/chenhongwu666/article/details/41965801Connect the camera device, you need to introduceAforge.video;AForge.Video.DirectShow;AForge.Video.FFMPEG;You also need to add a reference, Aforge.dll,aforge.video,aforge.video.directshow,aforge.control,aforge.video.ffmpeg,You also need to add Aforge.control in the Toolbox, and then find Videosourceplayer this control to add to the interfaceThen define the variablesPrivate Filterinfocollection videodevices;Private
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.